package com.example.controller;

import com.example.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * @author ：liukai
 * @date ：Created in 2021/9/6 11:07 上午
 * @description：
 * @modified By：
 * @version: $
 */
@RestController
@Slf4j
public class ProviderController {

    @Value("${server.port}")
    public int port;

    @Value("${config.info}")
    public String info;


    @GetMapping("/info")
    public String info() {
        return info;
    }

    @GetMapping("/provider/getById/{id}")
    public String getById(@PathVariable("id") int id) {
        return "端口号为:" + port + "的服务提供id成功：" + id;
    }

    @PostMapping("/provider/addUser")
    public String addUser(@RequestBody User user) throws InterruptedException {

        int time = 3;
        TimeUnit.SECONDS.sleep(time);
        log.info("添加成功：" + user.toString() + "等待时间：" + time);
        return "在端口号：" + port + "中添加成功";
    }

}
